import 'package:fish_redux/fish_redux.dart';
import 'package:flutter/material.dart' hide Action;
import 'package:www.znpigai.teacher/global_store/state.dart';
import 'package:www.znpigai.teacher/home_page/homework_list_component/item/state.dart';
import 'package:www.znpigai.teacher/utils/util.dart';

import 'action.dart';

Widget buildView(
    HomeworkState state, Dispatch dispatch, ViewService viewService) {
  String submitCount() {
    switch (state.status) {
      case "notStart":
        return "班级已提交${state.submittedCount}";
        break;
      case "underway":
        return "班级已提交${state.submittedCount}";
        break;
      case "finish":
        return "班级未提交${state.submittedCount}";
        break;
      case "reject":
        return "班级已提交${state.submittedCount}";
        break;
      case "remark":
        return "班级未提交${state.submittedCount}";
        break;
      case "notSubmit":
        return "班级已提交${state.submittedCount}";
        break;
      default:
        return "班级已提交${state.submittedCount}";
    }
  }

  MaterialColor statusColor() {
    switch (state.status) {
      case "notStart":
        return Colors.orange;
        break;
      case "underway":
        return Colors.orange;
        break;
      case "finish":
        return Colors.green;
        break;
      case "reject":
        return Colors.red;
        break;
      case "remark":
        return Colors.teal;
        break;
      case "notSubmit":
        return Colors.orange;
        break;
      default:
        return Colors.red;
    }
  }

  var score = '';
  if (state.status != "notStart") {
    if (state.teacherScore == '--.-') {
      score = '${state.machineScore ?? 0}分';
    } else {
      score = '${state.teacherScore}分';
    }
  }

  return Card(
    color: Colors.white,
    shape: RoundedRectangleBorder(
      borderRadius: BorderRadius.circular(15.0),
    ),
    elevation: 4.0,
    margin: new EdgeInsets.symmetric(horizontal: 10.0, vertical: 5.0),
    child: ListTile(
        onTap: () => dispatch(AnswerActionCreator.onClick()),
        title: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: <Widget>[
            Padding(
              padding: EdgeInsets.only(top: 10.0),
              child: Row(children: <Widget>[
                Text(
                  "【${state.statuscn}】",
                  style: TextStyle(color: statusColor(), fontSize: 15.0),
                ),
                Text(
                  state.title ?? '题目自拟',
                  style: TextStyle(color: Colors.black, fontSize: 15.0),
                ),
                Spacer(),
                Text(
                  score,
                  style: TextStyle(color: Colors.blue, fontSize: 15.0),
                )
              ]),
            ),
            Divider(height: 1),
            Padding(
                padding: EdgeInsets.only(top: 10.0),
                child: Text(
                  Util.plainText(state.demand,
                      defaultText: '无要求', maxLength: 50),
                )),
            Padding(
                padding: EdgeInsets.only(top: 10.0),
                child: Wrap(
                  spacing: 8.0,
                  runSpacing: 4.0,
                  children: <Widget>[
                    Container(
                      padding: const EdgeInsets.fromLTRB(4, 1, 4, 1),
                      decoration: new BoxDecoration(
                        border: new Border.all(color: Colors.grey),
                        borderRadius: BorderRadius.circular(4.0),
                      ),
                      child: Text(
                        state.classEntityName,
                        style: TextStyle(color: Colors.grey, fontSize: 12),
                      ),
                    ),
                    Container(
                      padding: const EdgeInsets.fromLTRB(4, 1, 4, 1),
                      decoration: new BoxDecoration(
                        border: new Border.all(color: Colors.grey),
                        borderRadius: BorderRadius.circular(4.0),
                      ),
                      child: Text(
                        GlobalState.types[state.articleType],
                        style: TextStyle(color: Colors.grey, fontSize: 12),
                      ),
                    ),
                    Container(
                      padding: const EdgeInsets.fromLTRB(4, 1, 4, 1),
                      decoration: new BoxDecoration(
                        border: new Border.all(color: Colors.grey),
                        borderRadius: BorderRadius.circular(4.0),
                      ),
                      child: Text(
                        submitCount(),
                        style: TextStyle(color: Colors.grey, fontSize: 12),
                      ),
                    ),
                    Container(
                      padding: const EdgeInsets.fromLTRB(4, 1, 4, 1),
                      decoration: new BoxDecoration(
                        border: new Border.all(color: Colors.grey),
                        borderRadius: BorderRadius.circular(4.0),
                      ),
                      child: Text(
                        "AI批改${state.aiCounter}次",
                        style: TextStyle(color: Colors.grey, fontSize: 12),
                      ),
                    ),
                  ],
                )),
            Padding(
                padding: EdgeInsets.only(top: 10.0),
                child: Row(
                  children: <Widget>[
                    Image.asset(
                      "assets/images/time.png",
                      width: 15,
                      height: 15,
                    ),
                    Text(
                      state.etime,
                      style: TextStyle(color: Colors.grey, fontSize: 12),
                    ),
                    SizedBox(width: 10),
                    Text(
                      state.ctime,
                      style: TextStyle(color: Colors.grey, fontSize: 12),
                    ),
                  ],
                )),
          ],
        )),
  );
}
